package tq.com.tqteacher.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class TQLookerOverInfo {
    private int count;
    private ArrayList<String> pics = new ArrayList<>();

    public TQLookerOverInfo(){};
    public TQLookerOverInfo(JSONObject pObject){
        refresh(pObject);
    }

    public void refresh(JSONObject pObject){
        if(pObject == null) return;

        count = pObject.optInt("total_reader");

        JSONArray lArray = pObject.optJSONArray("latest_reader");
        if(lArray == null){
            return;
        }
        for (int i = 0; i < lArray.length(); i++){
            try {
                JSONObject lObject = lArray.getJSONObject(i);
                TQUserInfo lUserInfo = new TQUserInfo();
                lUserInfo.refresh(lObject);

                String url = lUserInfo.getPic();
                pics.add(url);
            }catch (JSONException pE){
                pE.printStackTrace();
            }
        }
    }

    public int getCount() {
        return count;
    }

    public ArrayList<String> getPics() {
        return pics;
    }
}
